<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\store\model\jia;

use app\common\model\jia\WorksLog as WorksLogModel;
use think\facade\Db;
/**
 *
 * Class Time
 * @package app\store\model\article
 */
class WorksLog extends WorksLogModel
{
    public function getList(array $param = []): \think\Paginator
    {
        // 查询参数
        $params = $this->setQueryDefaultValue($param, [
            'title'   => '', // 文章标题
            'orderId' => '', // 文章分类id
             'betweenTime'   => [], // 起止时间
        ]);
        // 检索查询条件
        $filter = [];
        // 文章标题
        ! empty($params['title']) && $filter[] = ['name', 'like', "%{$params['title']}%"];

         // 起止时间
        if (! empty($params['betweenTime'])) {
            $times    = between_time($params['betweenTime']);
            $filter[] = ['l.create_time', '>=', $times['start_time']];
            $filter[] = ['l.create_time', '<', $times['end_time'] + 86400];
        }

        ! empty($params['orderId']) && $filter[] = ['l.order_no', '=', $params['orderId']];

       //  $list=Db::name('jia_works_log')->order('log_id desc')->select()->toArray();
       //  foreach ($list as $key => $value) {
       //    $realName=Db::name('order')->where('order_no',$value['order_no'])->value('real_name');
       // if($realName){
       //     Db::name('jia_works_log')->where('log_id',$value['log_id'])->update(['real_name'=>$realName]);
       // }
       //  }

        // 查询列表数据
        $data = $this->alias('l')
        ->join('jia_works w','w.works_id=l.works_id')
            ->where($filter)
            ->field('l.*,w.type')
            ->order(['l.create_time' => 'desc'])
            ->paginate(15);

        return $data;
    }
}
